import React, { Fragment, useEffect, useState } from "react";
let timer = null;
function Alert() {
    let [num, setNum] = useState(0);
    useEffect(() => {
        console.log("====componentDidMount====")
        timer = setInterval(() => setNum(num => num += 1), 1000);
    }, [])
    const clearincrement = () => {
        clearInterval(timer)
    }
    return (
        <Fragment>
            <div className="mt-3 alert alert-danger">当前数值为：{num}</div>
            <button className="btn btn-primary" onClick={clearincrement}>停止自增</button>
        </Fragment>
    )
}

export default Alert